/**
 * 
 */
package truerefactor.codesmell;

import java.util.List;

import truerefactor.graph.ClassNode;
import truerefactor.graph.CodeGraph;
import truerefactor.graph.CodeNode;
import truerefactor.graph.MethodNode;
import truerefactor.refactor.Refactoring;

/**
 * @author Isaac
 *
 */
public class DeadCode extends CodeSmell {

    /**
     * 
     */
    public DeadCode()
    {
        this.shortName = "DEDC";
        this.name = "Dead Code";
        this.description = "";
    }

    /*
     * (non-Javadoc)
     * @see truerefactor.codesmell.CodeSmell#measure(truerefactor.graph.CodeGraph, boolean, java.util.List)
     */
    @Override
    protected double measure(CodeGraph graph, boolean initial, List<List<Refactoring>> sequences)
    {
        double smell = 0;
        List<ClassNode> classes = graph.getClasses();
        
        for (ClassNode cNode : classes) {
            for (CodeNode node : cNode.getMethods()) {
                if (node instanceof MethodNode) {
                    int assoc = ((MethodNode) node).getAssociatedMethods().size();
                    int other = ((MethodNode) node).getOtherMethods().size();
                    
                    if ((assoc + other) == 0) {
                        smell++;
                    }
                }
            }
        }
        
        return smell;
    }
}
